/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.crawl.battle.command;

import com.rafkind.crawl.battle.BattleCommand;
import com.rafkind.crawl.battle.BattleListener;
import com.rafkind.crawl.battle.BattleResult;
import com.rafkind.crawl.data.Creature;
import com.rafkind.crawl.data.Effect;
import java.util.List;
import java.util.Random;

/**
 *
 * @author drafkind
 */
public class AttackCommand extends BattleCommand {

  private Random random;
  private Effect effect;

  public AttackCommand(Random random, Creature source, List<Creature> targets) {
    super(source, targets);
    this.random = random;
  }  
  
  @Override
  public BattleResult execute(List<BattleListener> listeners, Creature target) {
    
    int hitChance = getHitChance();
    int evadeChance = getEvadeChance();
    
    int number = random.nextInt(hitChance + evadeChance);
    
    if (number >= hitChance) {
      for (BattleListener b : listeners)
	b.attackHit(source, effect, target);
      
      int damageDone = getDamage() - getDamageAbsorbed();
      
      target.doDamage(damageDone);
      
      for (BattleListener b : listeners)
	b.attackDamage(source, effect, target, damageDone);
      
    } else {
      for (BattleListener b : listeners)
	b.attackMiss(source, effect, target);
    }
    
    return BattleResult.CONTINUE;
  }
  
  public int getHitChance() {
    return 1;
  }
  
  public int getEvadeChance() {
    return 1;
  }
  
  public int getDamage() {
    return 1;
  }
  
  public int getDamageAbsorbed() {
    return 0;
  }
}